import 'package:flutter/material.dart';
import '../Draw/point_values.dart';


import 'coordinate.dart';
import 'painter_box.dart';

void main() {
  runApp(const MydrawApp());
}

class MydrawApp extends StatelessWidget {
  const MydrawApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: '二维坐标系',//标题名
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget{
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool _showSliders = true;
  String _sliderStatus = "点我隐藏滑块";
  double _xSliderValue = 0.5;
  double _ySliderValue = 0.5;
  final PointVlaues pointVlaues = PointVlaues();
  // List<Offset> points = [
  //   Offset(0.12, 0.13),
  //   Offset(0.22, 0.31),
  //   Offset(0.24, 0.43),
  //   Offset(0.62, 0.53),
  //   Offset(0.72, 0.23),
  //   Offset(0.82, 0.13),
  //   Offset(0.32, 0.63),
  //   Offset(0.52, 0.83),
  // ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // floatingActionButton: FloatingActionButton(
      //   child: const Icon(Icons.add),
      //   onPressed: _pushPoint,
      // ),
      body: Center(
        child: Column(children: [

          Stack(children: [
            Padding(padding:  const EdgeInsets.all(6),
              child: RepaintBoundary(
                child: CustomPaint(
                  size: const Size(500, 500),//画板大小
                  painter: PainterBox(//绘制调用
                      pointVlaues,Coordinate(
                    xScaleCount: 10,//x轴间隔刻度
                    yScaleCount: 10,//y轴间隔刻度
                    originPointX: 0+((_xSliderValue-0.5)*20),
                    originPointY: 0+((_ySliderValue-0.5)*20),
                    // axisColor: Colors.red//轴线颜色
                    // strokeWidth: 2//轴线宽度
                  )
                  ),
                ),
              ),
            ),
            Positioned(child: Visibility(child: Slider(value: _xSliderValue, onChanged: (value) {
              setState(() {
                _xSliderValue = value;
              });
            }), visible: _showSliders,),bottom: 0,width: 500,),

            Positioned(child: Visibility(child: RotatedBox(
                quarterTurns: -1, // 设置旋转角度为90度，如果需要逆时针旋转，可设置为 -1
                child: Slider(value: _ySliderValue, onChanged: (value) {
                  setState(() {
                    _ySliderValue = value;
                  });
                })), visible: _showSliders,),left: 0,height: 500,),
          ],),
          InkWell(child: Container(padding: const EdgeInsets.all(5),color: Colors.black38,child: Container(color: Colors.white,width: 140,height: 40,child: Center(child: Text(_sliderStatus),),),),onTap: () {
            setState(() {
              if (_showSliders) {
                _showSliders = false;
                _sliderStatus = "点我显示滑块";
              } else {
                _showSliders = true;
                _sliderStatus ="点我隐藏滑块";
              }
            });
          },)
        ],)
      ),
    );
  }

  void _pushPoint() {
//     Offset newPoint = Offset.zero;
//     if(points.isNotEmpty){
//       for (int i = 0; i < points.length; i++){
//         newPoint = points[i];
//       }
//       // newPoint = points.last.translate(0.1, 0.1);
//     }
//     points = List.of(points)..add(newPoint);
//     print("=======points:$points===================");
//     setState(() {
//
//     });
  }
}